package com.csgc.camera.util

import android.content.Context
import android.net.Uri
import android.os.Build
import androidx.core.content.FileProvider
import java.io.File

object FileUtils {

     fun getUriForFile(context: Context, file: File): Uri {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
            return FileProvider.getUriForFile(context,context.packageName+".fileProvider",file)
        }
        return Uri.fromFile(file)
    }


    /**
     * 从路径中提取文件名
     */
    private fun getFileNameFromPath(path: String): String? {
        if (path.isEmpty()) {
            return null
        }
        val start = path.lastIndexOf("/")
        val end = path.lastIndexOf(".")
        return if (start != -1 && end != -1) {
            path.substring(start + 1, path.length)
        } else {
            null
        }
    }
}
